<?php
namespace app\wf\controller;
use \think\Db;
use think\Controller;
use \think\Request;
use \think\Session;
use app\common\controller\DirectoryPageBase;
class Comm extends DirectoryPageBase
{
	public function _initialize()
    {
        //$this->EnsName=$this->request->get("EnsName");
        //$this->Paras=$this->request->get("EnsName");
        parent::_initialize();
    }

	public function handler()
	{
		//类的类别
		$DoType=$this->request->get('DoType');
		//方法
		
		if($DoType=="HttpHandler"){
			$DoMethod=$this->request->get('DoMethod');
			$HttpHandler=new HttpHandler();
			return $HttpHandler->index($DoMethod);
		}
		if($DoType=="Entities_Init"){
			$EnsName=$this->request->get('EnsName');
			$Paras=$this->request->get('Paras');
			$EntitiesInit=new EntitiesInit();
			return $EntitiesInit->index($EnsName,$Paras);
		}
		if($DoType=="Entity_Init"){
			$EnName=$this->request->get('EnName');
			$PKVal=$this->request->get('PKVal');
			$EntityInit=new EntityInit();
			return $EntityInit->index($EnName,$PKVal);
		}
		if($DoType=="WebUser_Init"){
			$user=Session::get('user');
		
			$dept=Db::table('port_dept')
			->field('No,Name')
			->where('No',$user['FK_Dept'])
			->find();

			$array = array( //普通数组
				"CustomerName" => "驰骋工作流",
				"CustomerNo" =>"CCFlow",
				"EndJSON" => "0",
				"FK_Dept" =>$dept['No'],
				"FK_DeptName" => "",
				"FK_DeptNameOfFull" =>"",
				"GroupNo" => "0",
				"Name" => $user['Name'],
				"No" =>  $user['No'],
				"SID" => ""
				);
			return $array;
		}
		if($DoType=="Entity_RetrieveFromDBSources"){
			$EnName=$this->request->get('EnName');
			$PKVal=$this->request->get('PKVal');
			$RetrieveFromDBSources=new RetrieveFromDBSources();
			return $RetrieveFromDBSources->index($EnName,$PKVal);
		}
		if($DoType=="Entity_Update"){
			$param = $this->request->param(); 
		
			$EntityUpdate=new EntityUpdate();
			//修改节点名称
            if($param['enName']=='BP.WF.Node'){
				return $EntityUpdate->Node($param);
			}
			//修改mapdata表中的节点名称
			if($param['enName']=='BP.Sys.MapData'){
				return $EntityUpdate->MapData($param);
			}

			return $EntityUpdate->index($param);
		}
		if($DoType=="Entity_DoMethodReturnString"){
		
			return "清除成功.";
		}
		//连接线保存
		if($DoType=="Entity_Save"){
			$param=$this->request->param();

		   //向wf_direction表中添加一条数据
		   $num= Db::table('wf_direction')
		   ->data([
			   'MyPK'=>$param['MyPK'],
			   'FK_Flow'=>$param['FK_Flow'],
			   'Node'=>$param['Node'],
			   'ToNode'=>$param['ToNode'],
			   'IsCanBack'=>'',
			   'Dots'=>'',
			   ])
		   ->insert();
	     
			 return $num;
		}
	}
	
}
